package com.ktgj.other.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.common.core.annotation.Excel;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.Customer;
import com.ktgj.other.domain.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.other.domain.EtScenery;
import com.ktgj.other.service.IEtSceneryService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 景点Controller
 * 
 * @author ruoyi
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/scenery")
public class EtSceneryController extends BaseController
{
    @Autowired
    private IEtSceneryService etSceneryService;
    @Autowired
    private RemoteCustomerService remoteCustomerService;

    /**
     * 查询景点列表
     */
    @PreAuthorize(hasPermi = "other:scenery:list")
    @GetMapping("/list")
    public TableDataInfo list(EtScenery etScenery)
    {
        startPage();
        List<EtScenery> list = etSceneryService.selectEtSceneryList(etScenery);
        return getDataTable(list);
    }

    /**
     * 导出景点列表
     */
    @PreAuthorize(hasPermi = "other:scenery:export")
    @Log(title = "景点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EtScenery etScenery) throws IOException
    {
        List<EtScenery> list = etSceneryService.selectEtSceneryList(etScenery);
        ExcelUtil<EtScenery> util = new ExcelUtil<EtScenery>(EtScenery.class);
        util.exportExcel(response, list, "景点数据");
    }

    /**
     * 获取景点详细信息
     */
    @PreAuthorize(hasPermi = "other:scenery:query")
    @GetMapping(value = "/{etsceneryid}")
    public AjaxResult getInfo(@PathVariable("etsceneryid") Long etsceneryid)
    {
        return AjaxResult.success(etSceneryService.selectEtSceneryById(etsceneryid));
    }

    /**
     * 新增景点
     */
    @PreAuthorize(hasPermi = "other:scenery:add")
    @Log(title = "景点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EtScenery etScenery)
    {
        return toAjax(etSceneryService.insertEtScenery(etScenery));
    }

    /**
     * 修改景点
     */
    @PreAuthorize(hasPermi = "other:scenery:edit")
    @Log(title = "景点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EtScenery etScenery)
    {
        return toAjax(etSceneryService.updateEtScenery(etScenery));
    }

    /**
     * 删除景点
     */
    @PreAuthorize(hasPermi = "other:scenery:remove")
    @Log(title = "景点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{etsceneryids}")
    public AjaxResult remove(@PathVariable Long[] etsceneryids)
    {
        return toAjax(etSceneryService.deleteEtSceneryByIds(etsceneryids));
    }

    /**
     * 景点列表
     * */
    @PostMapping("/sceneryList")
    public TableDataInfo sceneryList(@RequestBody SceneryListVo sceneryListVo){
        startPage();
        List<EtScenery> etSceneryList;
        try {
            etSceneryList = etSceneryService.sceneryList(sceneryListVo);
        } catch (Exception e){
            return null;
        }

        return getDataTable(etSceneryList);
    }

    /**
     * 人气景点
     * */
    @PostMapping("/popular")
    public AjaxResult popular(){
        List<EtScenery> etSceneryList = etSceneryService.popular();
        return AjaxResult.success(etSceneryList);
    }

    /**
     * 景点详情
     * */
    @PostMapping("/attractionDetails")
    public AjaxResult attractionDetails(@RequestBody Map<String, Object> map){
        Long id = Long.valueOf(map.get("id").toString());
        AttractionDetailsVo attractionDetailsVo;
        try {
            attractionDetailsVo = etSceneryService.attractionDetails(id);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        return AjaxResult.success(attractionDetailsVo);
    }

    /**
     * 门票详情介绍
     * */
    @PostMapping("/introduce")
    public AjaxResult introduce(@RequestBody Map<String, Object> map){
        Long id = Long.valueOf(map.get("id").toString());
        IntroduceVo introduceVo = etSceneryService.introduce(id);
        return AjaxResult.success(introduceVo);
    }

    /**
     * 填写订单
     * */
    @PostMapping("/writeOrder")
    public AjaxResult writeOrder(HttpServletRequest request, @RequestBody WriteOrderVo writeOrderVo){
        WriteOrder writeOrder;
        try {
            writeOrder = etSceneryService.writeOrder(writeOrderVo, request);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        return AjaxResult.success(writeOrder);
    }
}
